package ThreadDemo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-10-13
 * Time: 10:36
 */
public class Demo12 {
    //线程等待join()
    //让thread线程优先结束
    private static Thread mainThread;
    public static void main(String[] args) throws InterruptedException {
        mainThread = Thread.currentThread();
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 90; i++) {
                System.out.println("hello,Thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        thread.start();

        thread.join(5000);//在main线程里调用thread.join()方法，则main是等待的一方，调用方法的一方为被等待的一方

        System.out.println("main线程先结束");
    }
}
